from tokenize import Double

import requests     #发送网络请求
import parsel

url = "https://www.che168.com/china/8_10/#pvareaid=100943"
headers = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
}
response = requests.get(url = url
                        , headers = headers)
response.encoding = 'gbk'
date_html = response.text
selector = parsel.Selector(date_html)


lis = selector.css('.viewlist_ul li')
for li in lis:
    try:
        name = li.css('.card-name::text').get()
        unit = li.css('.cards-unit::text').get()
        kmNumber = unit.split('／')[0]
        years = unit.split('／')[1]
        city = unit.split('／')[2]
        business = unit.split('／')[3]
        # print('helo')
        # price = float(li.css('.pirce em::text').get())
        price = float(li.css('.pirce em::text').get())
        # print(type(price))
        # print(price,end="   ")
        yprice = li.css('s::text').get()
        yprice = float(yprice[:-1])
        # print(type(yprice))
        # print(yprice)
        zhejiu = price/yprice
        # yprice = yprice[-1]
        print(name, kmNumber, years, city, business, price, yprice,zhejiu)
        # break
    except:
        pass

